const _ = require('lodash');
const userInfoFacade = require('../../app/facade/userInfo.server.facade.js');
module.exports = {
    addUserInfo : addUserInfo,
    getUserInfoByUserId : getUserInfoByUserId
}


function addUserInfo(req,res,next){
    let body = req.body;
    let userInfo = body.userInfo;
    if(_.isEmpty(userInfo)){
        return next(new Error('UserInfo is empty'));
    }else{
        userInfoFacade.addUserInfo(userInfo, (error,result)=>{
            if(error){
                return next(new Error(error));
            }else{
                return res.json(userInfo);
            }
        });
    }
}

function getUserInfoByUserId(req, res, next) {
    let params = req.params;
    let userId = params.userId;
    if (_.isEmpty(userId)) {
        return next(new Error('userId is empty'));
    } else {
        userInfoFacade.getUserInfoByUserId(userId, (error, result) => {
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
            // res.render('foodItem', result);
        }
    });
    }
}